<!DOCTYPE html>












  


<html class="theme-next gemini use-motion" lang="zh-CN">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">




  <meta name="google-site-verification" content="A_78WZOvfJTnffhkbRiXvoT0JZXLHHpQQ1lN0GVkPBU">









  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=7.2.0">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=7.2.0">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=7.2.0">


  <link rel="mask-icon" href="/images/logo.svg?v=7.2.0" color="#222">






<link rel="stylesheet" href="/css/main.css?v=7.2.0">






<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css?v=4.7.0">








<script id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '7.2.0',
    sidebar: {"position":"left","display":"always","offset":12,"onmobile":true},
    back2top: {"enable":true,"sidebar":true,"scrollpercent":true},
    copycode: {"enable":false,"show_result":false,"style":null},
    fancybox: false,
    mediumzoom: false,
    fastclick: false,
    lazyload: false,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    },
    translation: {
      copy_button: '复制',
      copy_success: '复制成功',
      copy_failure: '复制失败'
    }
  };
</script>

  <meta name="keywords" content="echototo666">
<meta property="og:type" content="website">
<meta property="og:title" content="echototo6666">
<meta property="og:url" content="http://www.echototo666.com/page/2/index.html">
<meta property="og:site_name" content="echototo6666">
<meta property="og:locale" content="zh-CN">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="echototo6666">



  <link rel="alternate" href="/atom.xml" title="echototo6666" type="application/atom+xml">



  
  
  <link rel="canonical" href="http://www.echototo666.com/page/2/">



<script id="page.configurations">
  CONFIG.page = {
    sidebar: "",
  };
</script>

  
  <title>echototo6666 - 站在巨人肩膀上，注定也要成为巨人的一部分</title>
  












  <noscript>
  <style>
  .use-motion .motion-element,
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-title { opacity: initial; }

  .use-motion .logo,
  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">

  
  
    
  

  <div class="container sidebar-position-left 
  page-home">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">echototo6666</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
    
      
        <h1 class="site-subtitle" itemprop="description">站在巨人肩膀上，注定也要成为巨人的一部分</h1>
      
    
    
  </div>

  <div class="site-nav-toggle">
    <button aria-label="切换导航栏">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>



<nav class="site-nav">
  
    <ul id="menu" class="menu">
      
        
        
        
          
          <li class="menu-item menu-item-home">

    
    
      
    

    
      
    

    <a href="/" rel="section"><i class="menu-item-icon fa fa-fw fa-home"></i> <br>首页</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-categories">

    
    
      
    

    
      
    

    <a href="/categories/" rel="section"><i class="menu-item-icon fa fa-fw fa-th"></i> <br>分类<span class="badge">6</span></a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-archives">

    
    
      
    

    
      
    

    <a href="/archives/" rel="section"><i class="menu-item-icon fa fa-fw fa-archive"></i> <br>归档<span class="badge">35</span></a>

  </li>

      
      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br>搜索</a>
        </li>
      
    </ul>
  

  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off" placeholder="搜索..." spellcheck="false" type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



</div>
    </header>

    
  
  

  

  <span class="exturl github-corner" data-url="aHR0cHM6Ly9naXRodWIuY29tL3dkeTMzMTY0NDc0MQ==" title="Follow me on GitHub" aria-label="Follow me on GitHub"><svg width="80" height="80" viewbox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"/><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"/><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"/></svg></span>



    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          
            

          
          <div id="content" class="content">
            
  <section id="posts" class="posts-expand">
    
      

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.echototo666.com/2019/07/27/shell_fifo/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Lip">
      <meta itemprop="description" content>
      <meta itemprop="image" content="https://avatars0.githubusercontent.com/u/9856659">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="echototo6666">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">
                
                
                <a href="/2019/07/27/shell_fifo/" class="post-title-link" itemprop="url">shell多进程控制</a>
              
            
          </h2>
        

        <div class="post-meta">
          

          
          
          

          
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2019-07-27 23:00:34" itemprop="dateCreated datePublished" datetime="2019-07-27T23:00:34+00:00">2019-07-27</time>
            </span>
          

          
            

            
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                
                  <span class="post-meta-item-text">更新于</span>
                
                <time title="修改时间：2020-03-24 02:40:06" itemprop="dateModified" datetime="2020-03-24T02:40:06+00:00">2020-03-24</time>
              </span>
            
          

          
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/linux/" itemprop="url" rel="index"><span itemprop="name">linux</span></a></span>

                
                
              
            </span>
          

          
            
            
          

          
          

          

          

          <br>
          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <blockquote>
<p>试想平时我们需要使用shell多进程搞一些事情。如果是小事情还好，如果是大事情的话，我们for循环启动多个进程在后台运行。假设for循环很大 启动了几千个进程。我们的机器能支撑的住吗？</p>
</blockquote>
<h2 id="FIFO管道"><a href="#FIFO管道" class="headerlink" title="FIFO管道"></a>FIFO管道</h2><p>它是一种文件类型，在文件系统中可以看到。FIFO中可以很好地解决在无关进程间数据交换的要求，并且由于它们是存在于文件系统中的，这也提供了一种比匿名管道更持久稳定的通信办法。</p>
<blockquote>
<p>$mkfifo [option] name…</p>
</blockquote>
<p>以下例来讲。我们把父shell进程PID绑定一个fifo管道，然后设定最大并发进程数3 。大概原理就是写入到fifo文件三个空行。然后后面我们不关心for循环中要启动多少个子进程，子进程运行完后会减去fifo文件中一条空行。达到一个<strong>窗口限流</strong>的效果。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br></pre></td><td class="code"><pre><span class="line">#!/bin/bash</span><br><span class="line"></span><br><span class="line">trap &apos;exec 6&gt;&amp;-; exec 6&lt;&amp;-; exit 0;&apos; INT</span><br><span class="line"></span><br><span class="line">#for ((i=1;i&lt;=10;i++));</span><br><span class="line">#do</span><br><span class="line">#</span><br><span class="line">#echo &apos;\n&apos;</span><br><span class="line">#done</span><br><span class="line"></span><br><span class="line">##网站域名</span><br><span class="line">site=&apos;www.echototo666.com&apos;</span><br><span class="line"></span><br><span class="line">#首页</span><br><span class="line">url_by_page=( $(curl -s $&#123;site&#125; |grep post-title-link |awk  &apos;&#123; print substr($2,6)&#125;&apos;|  sed  &apos;s/&quot;//g&apos;) )</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">#如果有其他页</span><br><span class="line">##接受页面变量</span><br><span class="line">if [ $# -gt 0 ];then</span><br><span class="line">have_page=$1</span><br><span class="line"></span><br><span class="line">for((i=2;i&lt;=$have_page;i++));</span><br><span class="line">do</span><br><span class="line">url=$site&quot;/page/&quot;$i&quot;/&quot;</span><br><span class="line">get_page=($(curl -s $&#123;url&#125; |grep post-title-link |awk  &apos;&#123; print substr($2,6)&#125;&apos;|  sed  &apos;s/&quot;//g&apos;) )</span><br><span class="line">url_by_page+=$&#123;get_page[@]&#125;</span><br><span class="line">done</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">fi</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">#至此获取到所有到页面url</span><br><span class="line">echo $&#123;url_by_page[@]&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">function flash()&#123;</span><br><span class="line">    ##传递的url参数</span><br><span class="line">    _url=$1</span><br><span class="line">    ref=&quot;Referer:http://$site$_url&quot;</span><br><span class="line">    i=0</span><br><span class="line">    tmp_arr=($&#123;uri//\// &#125;)</span><br><span class="line">    bar=$&#123;tmp_arr[3]&#125;&apos;:&apos;</span><br><span class="line">    while [ $i -le 100 ]</span><br><span class="line">    do</span><br><span class="line"></span><br><span class="line">        printf &quot;[%-100s][%d%%]\r&quot; &quot;$bar&quot; &quot;$i&quot;</span><br><span class="line"></span><br><span class="line">    let i++</span><br><span class="line">    ## 带上cookie时网站uv不变，只刷pv</span><br><span class="line">    curl -s \</span><br><span class="line">    -H $ref \</span><br><span class="line">    -A &quot;Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36&quot; \</span><br><span class="line">    --cookie &quot;busuanziId=C2B688C12EE64A93BE945853A895C3FA&quot; \</span><br><span class="line">    &apos;http://busuanzi.ibruce.info/busuanzi?jsonpCallback=BusuanziCallback_813017575528&apos; &gt; /dev/null</span><br><span class="line"></span><br><span class="line">        bar+=&apos;#&apos;</span><br><span class="line">    done</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">##其中$$为该进程的pid</span><br><span class="line">tmp_fifofile=&quot;/tmp/$$.fifo&quot;</span><br><span class="line">##创建命名管道</span><br><span class="line">mkfifo $tmp_fifofile</span><br><span class="line">##把文件描述符6和FIFO进行绑定</span><br><span class="line">exec 6&lt;&gt;$tmp_fifofile</span><br><span class="line">##绑定后，该文件就可以删除了</span><br><span class="line">rm -f $tmp_fifofile</span><br><span class="line"></span><br><span class="line">##并发量为3，用这个数字来控制并发数</span><br><span class="line">thread=13</span><br><span class="line">for ((i=0;i&lt;$thread;i++));</span><br><span class="line">do</span><br><span class="line">    ##写一个空行到管道里，因为管道文件的读取以行为单位</span><br><span class="line">    echo &gt;&amp;6</span><br><span class="line">done</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">for uri in $&#123;url_by_page[@]&#125;</span><br><span class="line">do</span><br><span class="line">##读取管道中的一行,每次读取后，管道都会少一行</span><br><span class="line">read -u6</span><br><span class="line">&#123;</span><br><span class="line">#tmp_arr=($&#123;uri//\// &#125;)</span><br><span class="line"></span><br><span class="line">#flash $uri &gt; ~/$&#123;tmp_arr[3]&#125;.log</span><br><span class="line">flash $uri || &#123;echo &quot;task is failed&quot;&#125;</span><br><span class="line">##每次执行完flash函数后，再增加一个空行，这样下面的进程才可以继续执行</span><br><span class="line">echo &gt;&amp;6</span><br><span class="line">&#125; &amp;</span><br><span class="line">done</span><br><span class="line">#tail -f file1 file2 | awk &apos;/^==&gt; / &#123;a=substr($0, 5, length-8); next&#125;  &#123;print a&quot;:&quot;$0&#125;&apos;</span><br><span class="line"></span><br><span class="line">wait</span><br><span class="line"></span><br><span class="line">##关闭文件描述符6的写</span><br><span class="line">exec 6&gt;&amp;-</span><br><span class="line">echo &quot;\n alldone&quot;</span><br></pre></td></tr></table></figure>
<h3 id="ps-最后遗留有一个问题，就是上面那个脚本是去刷页面访问量的flsah方法中又一个进度条。然后在命令行中运行父进程的时候，不同子进程中的进度条会有一个输出覆盖的bug"><a href="#ps-最后遗留有一个问题，就是上面那个脚本是去刷页面访问量的flsah方法中又一个进度条。然后在命令行中运行父进程的时候，不同子进程中的进度条会有一个输出覆盖的bug" class="headerlink" title="ps:最后遗留有一个问题，就是上面那个脚本是去刷页面访问量的flsah方法中又一个进度条。然后在命令行中运行父进程的时候，不同子进程中的进度条会有一个输出覆盖的bug"></a>ps:最后遗留有一个问题，就是上面那个脚本是去刷页面访问量的flsah方法中又一个进度条。然后在命令行中运行父进程的时候，不同子进程中的进度条会有一个输出覆盖的bug</h3>
          
        
      
    </div>

    

    

    
    
    

    

    
      
    
    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.echototo666.com/2019/05/27/shell_iconv/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Lip">
      <meta itemprop="description" content>
      <meta itemprop="image" content="https://avatars0.githubusercontent.com/u/9856659">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="echototo6666">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">
                
                
                <a href="/2019/05/27/shell_iconv/" class="post-title-link" itemprop="url">Navcat导出数据为csv乱码问题（iconv）</a>
              
            
          </h2>
        

        <div class="post-meta">
          

          
          
          

          
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2019-05-27 23:00:34" itemprop="dateCreated datePublished" datetime="2019-05-27T23:00:34+00:00">2019-05-27</time>
            </span>
          

          
            

            
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                
                  <span class="post-meta-item-text">更新于</span>
                
                <time title="修改时间：2020-03-24 02:40:06" itemprop="dateModified" datetime="2020-03-24T02:40:06+00:00">2020-03-24</time>
              </span>
            
          

          
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/linux/" itemprop="url" rel="index"><span itemprop="name">linux</span></a></span>

                
                
              
            </span>
          

          
            
            
          

          
          

          

          

          <br>
          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>这是因为navcat导出csv文件的编码格式是gbk，而我们用的excel是urf8。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ iconv -s -c -f UTF8 -t GBK &quot;vs活动.csv&quot; &gt; ./iconv.utf8.gbk.tmp</span><br><span class="line">$ mv iconv.utf8.gbk.tmp &quot;11111.csv&quot;</span><br></pre></td></tr></table></figure>

          
        
      
    </div>

    

    

    
    
    

    

    
      
    
    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.echototo666.com/2019/05/17/php_lock/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Lip">
      <meta itemprop="description" content>
      <meta itemprop="image" content="https://avatars0.githubusercontent.com/u/9856659">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="echototo6666">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">
                
                
                <a href="/2019/05/17/php_lock/" class="post-title-link" itemprop="url">并发锁</a>
              
            
          </h2>
        

        <div class="post-meta">
          

          
          
          

          
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2019-05-17 13:30:32" itemprop="dateCreated datePublished" datetime="2019-05-17T13:30:32+00:00">2019-05-17</time>
            </span>
          

          
            

            
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                
                  <span class="post-meta-item-text">更新于</span>
                
                <time title="修改时间：2020-03-24 02:40:06" itemprop="dateModified" datetime="2020-03-24T02:40:06+00:00">2020-03-24</time>
              </span>
            
          

          
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/php/" itemprop="url" rel="index"><span itemprop="name">php</span></a></span>

                
                
              
            </span>
          

          
            
            
          

          
          

          

          

          <br>
          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>####问题描述<br>在工作项目中，会遇到一些php并发访问去修改一个数据问题，如果这个数据不加锁，就会造成数据的错误。</p>
<h2 id="1-举例说明"><a href="#1-举例说明" class="headerlink" title="1. 举例说明"></a>1. 举例说明</h2><blockquote>
<p>如果有两个操作人(p和m)，都用用户编号100账户,分别在pc和手机端同时登陆，100账户总余额有1000，p操作人花200，m操作人花300。并发过程如下。<br>p操作人：<br>     1 取出用户的余额1000。<br>     2 支付后剩余 800 = 1000 - 200。<br>     3 更新后账户余额800。<br>m操作人：<br>       1 取出用户余额1000。<br>       2 支付后剩余700 = 1000 - 300。<br>       3 支付后账户余额700。<br>两次支付后，账户的余额居然还有700，应该的情况是花费了500，账户余额500才对。造成这个现象的根本原因，是并发的时候，p和m同时操作取到的余额数据都是1000。</p>
</blockquote>
<h2 id="2-加锁设计"><a href="#2-加锁设计" class="headerlink" title="2.加锁设计"></a>2.加锁设计</h2><p>锁的操作一般只有两步，一 获取锁(getLock)；二是释放锁(releaseLock)。但现实锁的方式有很多种，可以是文件方式实现；sql实现；redis实现；</p>
<h2 id="3-code"><a href="#3-code" class="headerlink" title="3.code"></a>3.code</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br></pre></td><td class="code"><pre><span class="line">&lt;?php</span><br><span class="line">namespace Lib;</span><br><span class="line">class LockSys</span><br><span class="line">&#123;</span><br><span class="line"></span><br><span class="line">	//const LOCK_TYPE_DB = &apos;SQLLock&apos;;  </span><br><span class="line">    const LOCK_TYPE_FILE = &apos;\Lib\FileLock&apos;;</span><br><span class="line">    const LOCK_TYPE_REDIS = &apos;\Lib\RedisLock&apos;;</span><br><span class="line"></span><br><span class="line">	private $_lock = null;  </span><br><span class="line">    private static $_supportLocks = array(&apos;FileLock&apos;, &apos;SQLLock&apos;, &apos;RedisLock&apos;); </span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">	public function __construct($type, $options = array())   </span><br><span class="line">    &#123;  </span><br><span class="line">        if(false == empty($type))</span><br><span class="line">        &#123;</span><br><span class="line">            $this-&gt;createLock($type, $options);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public function createLock($type, $options=array())</span><br><span class="line">    &#123;</span><br><span class="line">        $this-&gt;_lock = new $type();//实例化 锁</span><br><span class="line">        // $this-&gt;_lock = new RedisLock();//实例化 锁</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public function getLock($key, $timeout = ILock::EXPIRE)</span><br><span class="line">    &#123;  </span><br><span class="line">        if (false == $this-&gt;_lock instanceof ILock)</span><br><span class="line">        &#123;</span><br><span class="line">            throw new Exception(&apos;false == $this-&gt;_lock instanceof ILock&apos;);</span><br><span class="line">        &#125;</span><br><span class="line">        $this-&gt;_lock-&gt;getLock($key, $timeout);</span><br><span class="line">    &#125;  </span><br><span class="line"></span><br><span class="line">    public function releaseLock($key)  </span><br><span class="line">    &#123;  </span><br><span class="line">        if (false == $this-&gt;_lock instanceof ILock)</span><br><span class="line">        &#123;</span><br><span class="line">            throw new Exception(&apos;false == $this-&gt;_lock instanceof ILock&apos;);</span><br><span class="line">        &#125;</span><br><span class="line">        $this-&gt;_lock-&gt;releaseLock($key);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">interface ILock</span><br><span class="line">&#123;  </span><br><span class="line">    const EXPIRE = 5;</span><br><span class="line">    public function getLock($key, $timeout=self::EXPIRE);</span><br><span class="line">    public function releaseLock($key);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">//redis 锁</span><br><span class="line">class RedisLock implements ILock</span><br><span class="line">&#123;  </span><br><span class="line">    public function __construct()  </span><br><span class="line">    &#123;</span><br><span class="line">        $this-&gt;redis = getReidsInstance();</span><br><span class="line">        // $this-&gt;memcache = new Memcache();  </span><br><span class="line">    &#125;  </span><br><span class="line">  </span><br><span class="line">    public function getLock($key, $timeout=self::EXPIRE)</span><br><span class="line">    &#123;       </span><br><span class="line">        $waitime = 20000;  </span><br><span class="line">        $totalWaitime = 0;  </span><br><span class="line">        $time = $timeout*1000000;</span><br><span class="line">        // while ($totalWaitime &lt; $time &amp;&amp; false == $this-&gt;memcache-&gt;add($key, 1, $timeout))</span><br><span class="line">        while ($totalWaitime &lt; $time &amp;&amp; false == $this-&gt;redis-&gt;set($key, 1, array(&apos;nx&apos;,&apos;ex&apos;=&gt; $timeout) ))   </span><br><span class="line">        &#123;  </span><br><span class="line">            usleep($waitime);  </span><br><span class="line">            $totalWaitime += $waitime;  </span><br><span class="line">        &#125;  </span><br><span class="line">        if ($totalWaitime &gt;= $time)  </span><br><span class="line">            throw new Exception(&apos;can not get lock for waiting &apos;.$timeout.&apos;s.&apos;);  </span><br><span class="line">  </span><br><span class="line">    &#125;  </span><br><span class="line">  </span><br><span class="line">    public function releaseLock($key)  </span><br><span class="line">    &#123;  </span><br><span class="line">        $this-&gt;redis-&gt;delete($key);  </span><br><span class="line">    &#125;  </span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">//文件锁</span><br><span class="line">class FileLock implements ILock</span><br><span class="line">&#123;  </span><br><span class="line">    private $_fp;  </span><br><span class="line">    private $_single;  </span><br><span class="line">  </span><br><span class="line">    public function __construct($options)  </span><br><span class="line">    &#123;  </span><br><span class="line">        if (isset($options[&apos;path&apos;]) &amp;&amp; is_dir($options[&apos;path&apos;]))  </span><br><span class="line">        &#123;  </span><br><span class="line">            $this-&gt;_lockPath = $options[&apos;path&apos;].&apos;/&apos;;  </span><br><span class="line">        &#125;  </span><br><span class="line">        else  </span><br><span class="line">        &#123;  </span><br><span class="line">            $this-&gt;_lockPath = &apos;/tmp/&apos;;  </span><br><span class="line">        &#125;  </span><br><span class="line">         </span><br><span class="line">        $this-&gt;_single = isset($options[&apos;single&apos;])?$options[&apos;single&apos;]:false;  </span><br><span class="line">    &#125;  </span><br><span class="line">  </span><br><span class="line">    public function getLock($key, $timeout=self::EXPIRE)  </span><br><span class="line">    &#123;  </span><br><span class="line">        $startTime = Timer::getTimeStamp();  </span><br><span class="line">  </span><br><span class="line">        $file = md5(__FILE__.$key);  </span><br><span class="line">        $this-&gt;fp = fopen($this-&gt;_lockPath.$file.&apos;.lock&apos;, &quot;w+&quot;);  </span><br><span class="line">        if (true || $this-&gt;_single)  </span><br><span class="line">        &#123;  </span><br><span class="line">            $op = LOCK_EX + LOCK_NB;  </span><br><span class="line">        &#125;  </span><br><span class="line">        else  </span><br><span class="line">        &#123;  </span><br><span class="line">            $op = LOCK_EX;  </span><br><span class="line">        &#125;  </span><br><span class="line">        if (false == flock($this-&gt;fp, $op, $a))  </span><br><span class="line">        &#123;  </span><br><span class="line">            throw new Exception(&apos;failed&apos;);  </span><br><span class="line">        &#125;  </span><br><span class="line">         </span><br><span class="line">        return true;  </span><br><span class="line">    &#125;  </span><br><span class="line">  </span><br><span class="line">    public function releaseLock($key)  </span><br><span class="line">    &#123;  </span><br><span class="line">        flock($this-&gt;fp, LOCK_UN);  </span><br><span class="line">        fclose($this-&gt;fp);  </span><br><span class="line">    &#125;  </span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">?&gt;</span><br></pre></td></tr></table></figure>
<h2 id="4-应用锁"><a href="#4-应用锁" class="headerlink" title="4.应用锁"></a>4.应用锁</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">//单笔充值大于1w  或者 累计本金大于2w</span><br><span class="line">//单笔充值 小于1w 发放一张0.5阶梯加息劵 7天</span><br><span class="line">//发放1%加息 结束时间=阶梯加息活动结束时间</span><br><span class="line"></span><br><span class="line">//开启redis锁</span><br><span class="line">$lockSystem = new \Lib\LockSys(LockSys::LOCK_TYPE_REDIS);</span><br><span class="line">$lockKey = &quot;ladder.&quot;.$userId;</span><br><span class="line">$lockSystem-&gt;getLock($lockKey,3);//redis单机锁  延迟8秒</span><br><span class="line"></span><br><span class="line">#code......</span><br><span class="line">$lockSystem-&gt;releaseLock($lockKey);</span><br></pre></td></tr></table></figure>
<h2 id="5-锁分析"><a href="#5-锁分析" class="headerlink" title="5.锁分析"></a>5.锁分析</h2><p>当多个程序进程过来时（微秒级），对同一资源读取时，立马加上一个锁，然后紧接着的进程会获取到该锁（每0.02s 轮训一次）</p>

          
        
      
    </div>

    

    

    
    
    

    

    
      
    
    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.echototo666.com/2019/04/27/api_err/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Lip">
      <meta itemprop="description" content>
      <meta itemprop="image" content="https://avatars0.githubusercontent.com/u/9856659">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="echototo6666">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">
                
                
                <a href="/2019/04/27/api_err/" class="post-title-link" itemprop="url">api接口故障解决办法</a>
              
            
          </h2>
        

        <div class="post-meta">
          

          
          
          

          
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2019-04-27 12:11:33" itemprop="dateCreated datePublished" datetime="2019-04-27T12:11:33+00:00">2019-04-27</time>
            </span>
          

          
            

            
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                
                  <span class="post-meta-item-text">更新于</span>
                
                <time title="修改时间：2020-03-24 02:40:06" itemprop="dateModified" datetime="2020-03-24T02:40:06+00:00">2020-03-24</time>
              </span>
            
          

          
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/php/" itemprop="url" rel="index"><span itemprop="name">php</span></a></span>

                
                
              
            </span>
          

          
            
            
          

          
          

          

          

          <br>
          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h1 id="服务降级、熔断、限流、排队"><a href="#服务降级、熔断、限流、排队" class="headerlink" title="服务降级、熔断、限流、排队"></a>服务降级、熔断、限流、排队</h1><p>接口级故障：系统没有宕机、网络没有中断，但是业务却出现了问题：业务响应慢、大量访问超时、大量访问异常。</p>
<p>本质：系统负载过高，导致无法快速处理业务。比如，如果系统中存在慢查询，当负载过高时，慢查询会将数据库资源耗尽，导致读写操作超时，业务读写很容易出现超时现象。即使没有慢查询当负载过高时也会出现超时情况。</p>
<p>产生原因的内部条件：程序bug导致死循环、存在慢查询、程序逻辑不对导致耗尽内存</p>
<p>外部条件：黑客攻击、促销、第三方系统响应缓慢</p>
<h2 id="解决思路"><a href="#解决思路" class="headerlink" title="解决思路"></a>解决思路</h2><blockquote>
<p>解决接口级故障的核心思想是优先保障核心业务和优先保障绝大部分用户。比如登录功能很重要，当访问量过高时，停掉注册功能，为登录腾出资源。</p>
</blockquote>
<h2 id="解决策略"><a href="#解决策略" class="headerlink" title="解决策略"></a>解决策略</h2><h3 id="降级"><a href="#降级" class="headerlink" title="降级"></a>降级</h3><blockquote>
<p>系统将某些不重要的业务或接口的功能降低，可以只提供部分功能，也可以完全停到所有所有不重要的功能。降级的思想是丢车保帅。</p>
</blockquote>
<p>常见降级方式</p>
<ul>
<li><p>系统后门降级：系统预留后门用于降级，比如提供一个降级URL，访问URL时就执行降级指令。缺点：如果服务器数量多，需要一台一台去操作，效率低。</p>
</li>
<li><p>独立系统降级：将降级操作独立到一个单独的系统中，可以实现复杂的权限管理、批量操作等功能。</p>
</li>
</ul>
<h3 id="熔断"><a href="#熔断" class="headerlink" title="熔断"></a>熔断</h3><blockquote>
<p>降级是应对系统自身的故障，而熔断的目的是应对外部系统的故障。比如A服务的X功能依赖B服务的某个接口，当B服务接口响应很慢时，A服务X功能的响应也会被拖慢，进一步导致了A服务的线程都卡在了X功能上，A服务的其它功能也会卡主或拖慢。此时就需要熔断机制，即A服务不在请求B这个接口，A服务内部发现B接口就直接返回错误，从而避免整个A服务被拖慢。</p>
</blockquote>
<ul>
<li>实现思路：需要系统有一个统一的API调用层，由API来进行采样或者统计。</li>
</ul>
<h3 id="限流"><a href="#限流" class="headerlink" title="限流"></a>限流</h3><blockquote>
<p>限流：只允许系统能够承受的访问量进来，超出的会被丢弃。</p>
</blockquote>
<p>降级从系统功能优先级角度考虑如何应对故障，而限流则从用户访问压力的角度来考虑如何应对故障。<br>常见限流方式</p>
<ol>
<li>基于请求限流：指从外部请求的角度考虑限流。常见的方式有：</li>
</ol>
<ul>
<li>限制总量：限制某个指标的累积上限。比如直播间的用户总数上限为100万，超过后用户无法进入。抢购商品数量为100，限制抢购用户上限为1万个，超过或直接拒绝。</li>
<li>限制时间量：限制一段时间内某个指标的上限。例如：一分钟内只允许1000个用户访问。每秒请求峰值为10万。</li>
<li>都需要找到合适的阀值：需要通过性能压测来确定阀值或者逐步优化。</li>
</ul>
<ol start="2">
<li>基于资源限流：指从系统内部考虑，找到影响性能的关键资源，对其使用上限限制。常见的内部资源有：连接数、文件句柄、线程数、请求队列、CPU利用率等。例如，使用Netty实现服务器，每个请求先放到请求队列中，业务线程从请求队列中获取任务进行处理，请求队列大小为1000，那么超过该值则直接拒绝。 <h3 id="排队"><a href="#排队" class="headerlink" title="排队"></a>排队</h3></li>
</ol>
<blockquote>
<p>排队方式来应对接口级故障的方式是：让用户等待一段时间，而不是像限流方式直接拒绝用户。从体验上来讲，虽然用户没有很快得到拒绝响应，但是如果等待时间过长，体验也不是很好。(但是对于一些请求，等待比直接拒绝要好，比如支付请求，排队总比直接拒绝好，因为直接拒绝用户就有可能不买了）</p>
</blockquote>
<ul>
<li><p>实现方式：排队需要保存未被处理的请求，所以排队需要缓存大量数据，一般单个系统无法缓存这么多数据，所有需要单独的排队系统去实现。例如使用Kafka、RocketMQ等消息队列来缓存用户的请求。</p>
</li>
<li><p>实现思路：蓝色区域是排队系统</p>
</li>
</ul>
<p><img src="/img/Pasted1.png"></p>
<p>【排队模块】<br>负责将用户的请求以FIFO的方式存入队列中，不同商品的秒杀请求放在不同的队列中，队列大小可以根据秒杀商品数量自行定义。<br>【调度模块】<br>负责动态调度排队模块中的请求到服务模块中。动态性体现在：会根据服务模块的当前处理能力控制拉取请求速度，如果服务模块的处理能力有空闲就提升拉取请求速度，否则降慢速度。<br>【服务模块】<br>负责调用真正的业务来处理请求，并获取返回结果，再调用排队模块的接口写回业务处理结果。</p>
<p>转载：<span class="exturl" data-url="aHR0cHM6Ly93d3cuamlhbnNodS5jb20vcC8zM2YzOTRjMGVlMmQ=" title="https://www.jianshu.com/p/33f394c0ee2d">https://www.jianshu.com/p/33f394c0ee2d<i class="fa fa-external-link"></i></span></p>

          
        
      
    </div>

    

    

    
    
    

    

    
      
    
    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.echototo666.com/2018/07/25/insertSort/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Lip">
      <meta itemprop="description" content>
      <meta itemprop="image" content="https://avatars0.githubusercontent.com/u/9856659">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="echototo6666">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">
                
                
                <a href="/2018/07/25/insertSort/" class="post-title-link" itemprop="url">排序算法-插入排序</a>
              
            
          </h2>
        

        <div class="post-meta">
          

          
          
          

          
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2018-07-25 23:00:34" itemprop="dateCreated datePublished" datetime="2018-07-25T23:00:34+00:00">2018-07-25</time>
            </span>
          

          
            

            
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                
                  <span class="post-meta-item-text">更新于</span>
                
                <time title="修改时间：2020-03-24 02:40:06" itemprop="dateModified" datetime="2020-03-24T02:40:06+00:00">2020-03-24</time>
              </span>
            
          

          
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/算法/" itemprop="url" rel="index"><span itemprop="name">算法</span></a></span>

                
                
              
            </span>
          

          
            
            
          

          
          

          

          

          <br>
          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h1 id="插入排序"><a href="#插入排序" class="headerlink" title="插入排序"></a>插入排序</h1><ol>
<li>从第一个元素开始，该元素可以认为已经被排序</li>
<li>取出下一个元素，在已经排序的元素序列中从后向前扫描</li>
<li>如果该元素（已排序）大于新元素，将该元素移到下一位置</li>
<li>重复步骤3，直到找到已排序的元素小于或者等于新元素的位置</li>
<li>将新元素插入到该位置后</li>
<li>重复步骤2~5</li>
</ol>
<h1 id="动画演示"><a href="#动画演示" class="headerlink" title="动画演示"></a>动画演示</h1><p><img src="/img/insertSort.gif"></p>
<h1 id="代码"><a href="#代码" class="headerlink" title="代码"></a>代码</h1><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">function StraightInsertionSort($arr)&#123;</span><br><span class="line">    // 数组第一个元素默认已被排序</span><br><span class="line">    for ($i = 1; $i &lt; count($arr); $i++) &#123;// 未排序序列从数组第二个元素开始</span><br><span class="line">        $get = $arr[$i];// 获取未排列序列第一个元素为要比较的元素</span><br><span class="line">        // 指针指向已排序序列最后一个元素</span><br><span class="line">        $j = $i - 1;</span><br><span class="line">        while ($j &gt;= 0 &amp;&amp; $arr[$j] &gt; $get) &#123;// 当指针指向的元素比要比较的元素大</span><br><span class="line">            $arr[$j + 1] = $arr[$j];    // 则将指针指向的元素向后移动一位</span><br><span class="line">            $j--;// 指针前移</span><br><span class="line">        &#125;</span><br><span class="line">        // 直到指针指向的元素与要比较元素小或者相等，则要比较元素插入到指针指向元素后</span><br><span class="line">        $arr[$j + 1] = $get;</span><br><span class="line">    &#125;</span><br><span class="line">    return $arr;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

          
        
      
    </div>

    

    

    
    
    

    

    
      
    
    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
  </section>

  
  <nav class="pagination">
    <a class="extend prev" rel="prev" href="/"><i class="fa fa-angle-left" aria-label="上一页"></i></a><a class="page-number" href="/">1</a><span class="page-number current">2</span><a class="page-number" href="/page/3/">3</a><span class="space">&hellip;</span><a class="page-number" href="/page/7/">7</a><a class="extend next" rel="next" href="/page/3/"><i class="fa fa-angle-right" aria-label="下一页"></i></a>
  </nav>



          </div>
          

        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      

      <div class="site-overview-wrap sidebar-panel sidebar-panel-active">
        
       <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  
    <img class="site-author-image" itemprop="image" src="https://avatars0.githubusercontent.com/u/9856659" alt="Lip">
  
  <p class="site-author-name" itemprop="name">Lip</p>
  <div class="site-description motion-element" itemprop="description"></div>
</div>


  <nav class="site-state motion-element">
    
      <div class="site-state-item site-state-posts">
        
          <a href="/archives/">
        
          <span class="site-state-item-count">35</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
    

    
      
      
      <div class="site-state-item site-state-categories">
        
          
            <a href="/categories/">
          
        
        
        
          
        
          
        
          
        
          
        
          
        
          
        
        <span class="site-state-item-count">6</span>
        <span class="site-state-item-name">分类</span>
        </a>
      </div>
    

    
      
      
      <div class="site-state-item site-state-tags">
        
          
            <a href="/tags/">
          
        
        
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
        <span class="site-state-item-count">16</span>
        <span class="site-state-item-name">标签</span>
        </a>
      </div>
    
  </nav>



  <div class="feed-link motion-element">
    <a href="/atom.xml" rel="alternate">
      <i class="fa fa-rss"></i>RSS
    </a>
  </div>





  <div class="links-of-author motion-element">
    
      <span class="links-of-author-item">
      
      
      
        
      
        <a href="/13126666448" title="WeChat &rarr; 13126666448"><i class="fa fa-fw fa-wechat"></i></a>
      </span>
    
      <span class="links-of-author-item">
      
      
      
        
      
        <span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL3dkeTMzMTY0NDc0MQ==" title="GitHub &rarr; https://github.com/wdy331644741"><i class="fa fa-fw fa-github"></i></span>
      </span>
    
      <span class="links-of-author-item">
      
      
      
        
      
        <span class="exturl" data-url="bWFpbHRvOjEzMDE1NTMxNzE3QDE2My5jb20=" title="E-Mail &rarr; mailto:13015531717@163.com"><i class="fa fa-fw fa-envelope"></i></span>
      </span>
    
      <span class="links-of-author-item">
      
      
      
        
      
        <span class="exturl" data-url="aHR0cHM6Ly93ZWliby5jb20vZWNob3RvdG82NjY=" title="Weibo &rarr; https://weibo.com/echototo666"><i class="fa fa-fw fa-weibo"></i></span>
      </span>
    
      <span class="links-of-author-item">
      
      
      
        
      
        <span class="exturl" data-url="aHR0cHM6Ly93d3cuZmFjZWJvb2suY29tL2VjaG90b3RvNjY2" title="FB Page &rarr; https://www.facebook.com/echototo666"><i class="fa fa-fw fa-facebook"></i></span>
      </span>
    
      <span class="links-of-author-item">
      
      
      
        
      
        <span class="exturl" data-url="aHR0cHM6Ly9zdGFja292ZXJmbG93LmNvbS91c2Vycy85OTY3MzcxL2Rvbmd5YW5nLXdhbmc=" title="StackOverflow &rarr; https://stackoverflow.com/users/9967371/dongyang-wang"><i class="fa fa-fw fa-stack-overflow"></i></span>
      </span>
    
  </div>







          
        </div>
        
        <script type="text/javascript" charset="utf-8" src="/js/tagcloud.js"></script>
        <script type="text/javascript" charset="utf-8" src="/js/tagcanvas.js"></script>
        <div class="widget-wrap">
          <h3 class="widget-title">Tag Cloud</h3>
          <div id="myCanvasContainer" class="widget tagcloud">
            <canvas width="250" height="250" id="resCanvas" style="width=100%">
              <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/tags/IoC/">IoC</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/api/">api</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/awk/">awk</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/c/">c</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/debug/">debug</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/git/">git</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/laravel/">laravel</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/linux/">linux</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mac/">mac</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mysql/">mysql</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/php/">php</a><span class="tag-list-count">5</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/react/">react</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/redis/">redis</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/shell/">shell</a><span class="tag-list-count">10</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/webpack/">webpack</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/设计模式/">设计模式</a><span class="tag-list-count">1</span></li></ul>
            </canvas>
          </div>
        </div>
        
      </div>

      

      
        <div class="back-to-top motion-element">
          <i class="fa fa-arrow-up"></i>
          
            <span id="scrollpercent"><span>0</span>%</span>
          
        </div>
      

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">  <span class="exturl" data-url="aHR0cDovL3d3dy5iZWlhbi5taWl0Lmdvdi5jbg==">echototo666 </span>&copy; 2017 – <span itemprop="copyrightYear">2020</span>
  <span class="with-love" id="animate">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Lip</span>

  

  
</div>











<div class="BbeiAn-info"">
  京ICP备 -
  <a href="http://beian.miit.gov.cn/">20007883号</a>
  
</div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="post-meta-item-icon">
      <i class="fa fa-user"></i>
    </span>
    <span class="site-uv" title="总访客量">
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
    </span>
  

  
    <span class="post-meta-divider">|</span>
  

  
    <span class="post-meta-item-icon">
      <i class="fa fa-eye"></i>
    </span>
    <span class="site-pv" title="总访问量">
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
    </span>
  
</div>









        
      </div>
    </footer>

    

    

    
  </div>

  

<script>
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>










  
  















  
  <script src="/lib/jquery/index.js?v=3.4.1"></script>

  
  <script src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>




  <script src="/js/utils.js?v=7.2.0"></script>

  <script src="/js/motion.js?v=7.2.0"></script>



  
  


  <script src="/js/affix.js?v=7.2.0"></script>

  <script src="/js/schemes/pisces.js?v=7.2.0"></script>




  

  <script src="/js/next-boot.js?v=7.2.0"></script>

  

  
  <script src="/js/exturl.js?v=7.2.0"></script>


  

  

  

  

  

  

  



  




  
  <script>
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url).replace(/\/{2,}/g, '/');
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x"></i></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x"></i></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  




  



<script>
// GET RESPONSIVE HEIGHT PASSED FROM IFRAME

window.addEventListener("message", function(e) {
  var data = e.data;
  if ((typeof data === 'string') && (data.indexOf('ciu_embed') > -1)) {
    var featureID = data.split(':')[1];
    var height = data.split(':')[2];
    $(`iframe[data-feature=${featureID}]`).height(parseInt(height) + 30);
  }
}, false);
</script>


  
  <script>
    (function(){
      var bp = document.createElement('script');
      var curProtocol = window.location.protocol.split(':')[0];
      bp.src = (curProtocol === 'https') ? 'https://zz.bdstatic.com/linksubmit/push.js' : 'http://push.zhanzhang.baidu.com/push.js';
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(bp, s);
    })();
  </script>


  

  


  

</body>
</html>
